<?php

namespace Addons\Ask\Model;

use Home\Model\WeixinModel;

/**
 * Ask的微信模型
 */
class WeixinAddonModel extends WeixinModel
{
    function reply($dataArr, $keywordArr = array())
    {
        $map ['token'] = get_token();
        if (!empty ($keywordArr ['aim_id'])) {
            $map ['id'] = $keywordArr ['aim_id'];
        }

        $info = M('ask')->where($map)->order('id desc')->find();
        if (!$info) {
            return false;
        }

        // 其中token和openid这两个参数一定要传，否则程序不知道是哪个微信用户进入了系统
        $param ['ask_id'] = $info ['id'];
        $param ['token'] = get_token();
        $param ['openid'] = get_openid();
        $url = addons_url('Ask://Ask/show', $param);

        // 组装微信需要的图文数据，格式是固定的
        $articles [0] = array(
            'Title' => $info ['title'],
            'Description' => $info ['intro'],
            'PicUrl' => get_cover_url($info ['cover']),
            'Url' => $url
        );

        $res = $this->replyNews($articles);
    }
}
        	